package org.cfx.org.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.cfx.auth.domain.dto.LoginDto;
import org.cfx.basic.service.impl.BaseServiceImpl;
import org.cfx.basic.util.RolePermissionCount;
import org.cfx.basic.vo.UserExportVO;
import org.cfx.org.domain.Employee;
import org.cfx.org.mapper.EmployeeMapper;
import org.cfx.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author RTX 9090
 */
@Service
@Slf4j
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Map<String,List> getRolePermissionCount() {
        List<RolePermissionCount> rolePermissionCount = employeeMapper.getRolePermissionCount();
        Map<String, List> longStringMap = new HashMap<>();
        List<Long> longs = new ArrayList<>();
        List<String> name = new ArrayList<>();
        rolePermissionCount.forEach(r->{
            longs.add(r.getValue());
            name.add(r.getName());
        });
        longStringMap.put("count",longs);
        longStringMap.put("name",name);
        return longStringMap;
    }

    @Override
    public List<RolePermissionCount> getRole() {
        return employeeMapper.getRole();
    }

    @Override
    public UserExportVO getRoleById(Long id) {
        UserExportVO roleById = employeeMapper.getRoleById(id);
        roleById.setDeptName(roleById.getDepartment().getName());
        return roleById;
    }

    @Override
    public Employee login2(LoginDto loginDto) {
        return employeeMapper.login2(loginDto);
    }


}
